package co.baiku.boot.response;

import co.baiku.boot.common.tools.AESTools;
import co.baiku.boot.common.tools.StringTools;
import co.baiku.boot.response.item.WeixinRefundNoticeRecord;
import com.github.wxpay.sdk.WXPayUtil;
import org.apache.commons.beanutils.BeanUtils;

import java.util.Map;

/**
 * 微信服务商退款通知结果信息封装
 */
public class WeixinRefundNoticeResponse extends WeixinPayResponse {
    /**
     * 退款加密信息
     */
    private String req_info;

    public String getReq_info() {
        return req_info;
    }

    public void setReq_info(String req_info) {
        this.req_info = req_info;
    }

    public WeixinRefundNoticeRecord getRefundRecord(String secrect) throws Exception {
        if (StringTools.isBlank(req_info)) {
            return null;
        }
        String data = AESTools.decryptData(req_info, secrect);
        Map<String, String> recordMap = WXPayUtil.xmlToMap(data);
        WeixinRefundNoticeRecord refundNoticeRecord = new WeixinRefundNoticeRecord();
        BeanUtils.populate(refundNoticeRecord, recordMap);
        return refundNoticeRecord;
    }
}
